function axios(conf){
    let method = conf.method || 'GET';
    let url = conf.url || ''
    let headers = conf.headers;
    let transformRequest = conf.transformRequest || [];
    let data = conf.data || {};
    let resType = 'json';
    let xhr = new XMLHttpRequest();
    let sendData = data;
    let contType = '';
    xhr.open(method, url)
    for(let name in headers){
        xhr.setRequestHeader(name, headers[name])
        if(name == 'Content-Type'){
            contType = headers[name];
        }
    }
    if(contType === 'application/x-www-form-urlencoded'){
        for(let i=0; i<transformRequest.length; i++){
            sendData = transformRequest[i](sendData);
        }
    }
    if(contType === 'application/json' || contType === 'application/json; charset=UTF-8'){
        sendData = JSON.stringify(sendData);
    }
    xhr.responseType = resType;
    xhr.send(sendData);

    
    return new Promise((resolve, reject)=>{
        xhr.onreadystatechange = function(){
            if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
                console.log(xhr.response)
                resolve(xhr.response)
            }
        }
        xhr.onerror = function(err){
            reject(err)
        }
    })
}

module.exports = axios;